﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;

namespace TLSharp
{
    public class GameRequest
    {
        public string MessageType = "";
        public bool bChallenge = false;
        public DateTime DateAdded;

        public int GameRequestID;
        public double MaxDistance;
        public int MinRank;
        public int MaxRank;
        public double RequestLat;
        public double RequestLong;
        public int RequestingTeamID;
        public int TargetTeamID;
        public string ChallengingTeam;
        public string TargetTeam;

        private Team _ChallengingTeamObject;
        private Team _TargetTeamObject;
        public Team ChallengingTeamObject
        {
            get
            {
                if (_ChallengingTeamObject == null && (ChallengingTeam != null && ChallengingTeam.Length > 0))
                {
                    Newtonsoft.Json.Linq.JObject o = JObject.Parse(ChallengingTeam);

                    _ChallengingTeamObject  = (Team)(new JsonSerializer()).Deserialize(new JsonTokenReader(o), typeof(Team));

                }
                return _ChallengingTeamObject;
            }
        }

        public Team TargetTeamObject
        {
            get
            {
                if (_TargetTeamObject == null && (TargetTeam != null && TargetTeam.Length > 0))
                {
                    Newtonsoft.Json.Linq.JObject o = JObject.Parse(TargetTeam);

                    _TargetTeamObject  = (Team)(new JsonSerializer()).Deserialize(new JsonTokenReader(o), typeof(Team));

                }
                return _TargetTeamObject;
            }
        }
    }
}
